<?php
	session_start();
	$_SESSION["Host"] = "http://23.21.84.9/";
	header( "Content-Type: text/html");
	include("mysql_connect.php");
	
	$strKeyWord = $_POST['SelectKey'];
	
	$strCheckPage = $_POST['CheckPage'];
	
//	$strHref =  $_POST['Href'];
	
	$strSqlCommand = "SELECT FirstName, LastName , AgentID FROM REAgent";
	
	if(strlen($strKeyWord) > 0)
		$strSqlCommand .= " WHERE FirstName LIKE '%".$strKeyWord."%' OR LastName LIKE '%".$strKeyWord."%'";
	
	$strSqlCommand .= " ORDER BY LastName LIMIT 0, 30";
	
	$result = mysql_query($strSqlCommand);

	//$ArrayAgent = array("Kevin Adams","Amelia Ahne","Sabastion Battaglia","Harold Cannily");
	
//	echo '<li data-role="list-divider" role="heading">A</li>';
	//foreach($ArrayAgent as $strName)
	$Divider = "0";
	$nIdx = 0;
	$nRowNum = @mysql_num_rows($result);
	while($rowMedia = @mysql_fetch_row($result))	
	{
		$nIdx++;
		if(strncmp( $rowMedia[1], $Divider, 1) != 0)
		{
			if(strcmp($Divider,"0")==0)
			{
				echo '<li class="ui-li ui-li-divider ui-bar-b ui-corner-top" data-role="list-divider" role="heading" data-theme="b" data-inset="true">';
			}
			else
			{
				echo '<li class="ui-li ui-li-divider ui-bar-b" data-role="list-divider" role="heading" data-theme="b" data-inset="true">';
			}
			$Divider = substr($rowMedia[1],0,1);
			
			echo $Divider;
			echo '</li>';		
		}
		if($nIdx == $nRowNum)
		{
			echo '<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-li ui-corner-bottom ui-btn-up-c" 
					data-theme="c" data-corners="false" data-shadow="false" data-iconshadow="true" data-iconsize="18" 
					data-wrapperels="div" data-icon="arrow-r" data-iconpos="right">';
		}
		else
		{
			echo '<li class="ui-btn ui-btn-icon-right ui-li-has-arrow ui-li ui-btn-up-c" 
					data-theme="c" data-corners="false" data-shadow="false" data-iconshadow="true" data-iconsize="18" 
					data-wrapperels="div" data-icon="arrow-r" data-iconpos="right">';
		}
		echo '<div class="ui-btn-inner ui-li">';
		echo '<div class="ui-btn-text">';
		
		if( $strCheckPage == "page5" )
		{
			echo '<a class="ui-link-inherit AgentSelect" href="#page11" data-transition="slide" id="'.$rowMedia[2].'">';
		}
		else
		{
			echo '<a class="ui-link-inherit AgentSelect" href="#page6" data-transition="slide" id="'.$rowMedia[2].'">';
		}
		echo $rowMedia[0].' '.$rowMedia[1];		
		echo '</a>';
		echo '</div>';
		echo '<span class="ui-icon ui-icon-arrow-r ui-icon-shadow ui-iconsize-18">&nbsp;</span>';
		echo '</div>';
		echo '</li>';
	}
?>
